//
//  RegisterViewController.m
//  Mall
//
//  Created by 孙飞燕 on 16/10/18.
//  Copyright © 2016年 孙飞燕. All rights reserved.
//

#import "RegisterViewController.h"
#import "PersonalCenterViewController.h"
#import "SMSSDKUI.h"

@interface RegisterViewController ()
@property (nonatomic,strong)UILabel *accountLabel; //账号
@property (nonatomic,strong)UITextField *accountTF;
@property (nonatomic,strong)UILabel *passwordLabel;//密码
@property (nonatomic,strong)UITextField *passwordTF;
@property (nonatomic,strong)UIButton *finishBtn; //完成按钮
@property (nonatomic,strong)UIButton *phoneBtn;

@end

@implementation RegisterViewController
- (UIButton *)phoneBtn{
    if (!_phoneBtn) {
        _phoneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _phoneBtn.frame = CGRectMake(230, 100, 80, 30);
        [_phoneBtn addTarget:self action:@selector(phoneAction:) forControlEvents:UIControlEventTouchUpInside];
        [_phoneBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    }
    return _phoneBtn;
}
- (UILabel *)accountLabel{
    if (!_accountLabel) {
        _accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 50, 30)];
        _accountLabel.text = @"账户";

    }
    return _accountLabel;
}

- (UITextField *)accountTF{
    if (!_accountTF) {
        _accountTF = [[UITextField alloc]initWithFrame:CGRectMake(80, 100, 150, 30)];
        _accountTF.placeholder = @"请输入手机号码";
        [self.view addSubview:_accountTF];

    }
    return _accountTF;
}
- (UILabel *)passwordLabel{
    if (!_passwordLabel) {
        _passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 150, 80, 30)];
        _passwordLabel.text = @"密码";
        [self.view addSubview:_passwordLabel];

    }
    return _passwordLabel;
}

- (UITextField *)passwordTF{
    if (!_passwordTF) {
        _passwordTF = [[UITextField alloc]initWithFrame:CGRectMake(80, 150, 100, 30)];
        _passwordTF.placeholder = @"请输验证码";
        [self.view addSubview:_passwordTF];

    }
    return _passwordTF;
}
- (UIButton *)finishBtn{
    if (!_finishBtn) {
        _finishBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _finishBtn.frame = CGRectMake(100, 200, 50, 30);
        [_finishBtn addTarget:self action:@selector(finishAction:) forControlEvents:UIControlEventTouchUpInside];
        [_finishBtn setTitle:@"验证" forState:UIControlStateNormal];
        [self.view addSubview:_finishBtn];

    }
    return _finishBtn;
}
- (void)phoneAction:(UIButton *)sender{
    //SMSGetCodeMethodSMS：表示通过文本短信方式获取验证码
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.accountTF.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
        if (error) {
            NSLog(@"wolfhous提交手机未成功%@",error);
        }else{
            NSLog(@"wolfhous提交手机号成功");
        }
    }];
}
- (void)finishAction:(UIButton *)sender{

  [SMSSDK commitVerificationCode:self.passwordTF.text phoneNumber:self.accountTF.text zone:@"86" result:^(SMSSDKUserInfo *userInfo, NSError *error) {
      if (error) {
          NSLog(@"wolfhous验证码失败%@",error);
      }else{
          NSLog(@"wolfhosu验证码成功");
      }

         PersonalCenterViewController *pcVC = [[PersonalCenterViewController alloc]init];
         [self.navigationController pushViewController:pcVC animated:YES];

  }];


}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.accountLabel];
    [self.view addSubview:self.accountTF];
    [self.view addSubview:self.passwordLabel];
    [self.view addSubview:self.passwordTF];
    [self.view addSubview:self.phoneBtn];
    [self.view addSubview:self.finishBtn];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
